<template>
  <div class="service">
    <div class="header">
    </div>
    <div class="service-list">
      <div class="list-box">
        <ul class="listOne">
          <li @click="showStudents('feedback')">
            <div class="feed">
              <svg
                class="iconFont"
                aria-hidden="true"
              >
                <use xlink:href="#icon-fankui"></use>
              </svg>
            </div>
            <p>课堂反馈</p>
          </li>

          <li @click="showStudents('report')">
            <div class="report">
              <svg
                class="iconFont"
                aria-hidden="true"
              >
                <use xlink:href="#icon-zhenduanfenxi"></use>
              </svg>
            </div>
            <p>学业诊断</p>
          </li>

          <li @click="redirectUrl('schedule')">
            <div class="schdule">
              <svg
                class="iconFont"
                aria-hidden="true"
              >
                <use xlink:href="#icon-kebiao"></use>
              </svg>
            </div>
            <p>我的课表</p>
          </li>

          <li @click="redirectUrl('course')">
            <div class="course-s">
              <svg
                class="iconFont"
                aria-hidden="true"
              >
                <use xlink:href="#icon-kecheng2"></use>
              </svg>
            </div>
            <p>我的课程</p>
          </li>
        </ul>
        <ul class="listTwo">
          <li @click="redirectUrl('assessment')">
            <div class="pinggu">
              <svg
                class="iconFont"
                aria-hidden="true"
              >
                <use xlink:href="#icon-pinggu"></use>
              </svg>
            </div>
            <p>学前评估</p>
          </li>

          <li @click="redirectUrl('adjust-course')">
            <div class="linshi">
              <svg
                class="iconFont"
                aria-hidden="true"
              >
                <use xlink:href="#icon-yiqitiaodongjilu"></use>
              </svg>
            </div>
            <p>临时调课</p>
          </li>
          <li
            class="addStudent"
            @click="addStudent"
          >
            <div class="addStudentIcon">
              <svg
                class="iconFont"
                aria-hidden="true"
              >
                <use xlink:href="#icon-zengjia"></use>
              </svg>
            </div>
            <p>增加学员</p>
          </li>
          <li
            class="lessStudent"
            @click="lessStudent"
          >
            <div class="addStudentIcon">
              <svg
                class="iconFont"
                aria-hidden="true"
              >
                <use xlink:href="#icon-jianshao-"></use>
              </svg>
            </div>
            <p>解绑学员</p>
          </li>
        </ul>

        <ul class="listThree">
          <li @click="xuankeHome">
            <div class="xuanke">
              <svg
                class="iconFont"
                aria-hidden="true"
              >
                <use xlink:href="#icon-xuanke"></use>
              </svg>
            </div>
            <p>选课报读</p>
          </li>

          <router-link
            to="/nearby"
            tag="li"
          >
            <div class="school">
              <svg
                class="iconFont"
                aria-hidden="true"
              >
                <use xlink:href="#icon-xiaoqu"></use>
              </svg>
            </div>
            <p>全部校区</p>
          </router-link>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
import api from 'util/xhr'
import conf from 'conf/index'
import { mapState, mapActions } from 'vuex'
export default {
  components: {},
  data() {
    return {
      selectType: '',
      accessToken: sessionStorage.getItem('accessToken'),
      backUrl: document.location.href,
      showSelectStudent: false,
      selectedStudent: '',
      areamTeamId: sessionStorage.getItem('globalAreaTeamId')
        ? sessionStorage.getItem('globalAreaTeamId')
        : '564701030634225664'
    }
  },
  created() {},
  computed: {
    ...mapState({
      studentList: state => {
        return state.studentList
      },
      currentStudent: state => {
        return state.currentStudent
      }
    })
  },
  methods: {
    ...mapActions({
      loadStudent: 'loadStudent'
    }),
    xuankeHome() {
      window.location.href = `${conf.netSignUp}`
    },
    lessStudent() {
      window.location.href = `${conf.netSignUp}/personal/myStudents`
    },
    addStudent() {
      window.location.href = `${
        conf.netSignUp
      }/student/toAddAndBind?redirectURL=${conf.netSignUp}/index.html`
    },
    redirectUrl(type) {
      if (type === 'assessment') {
        this.goAssessment()
      } else {
        this.loadStudent().then(() => {
          if (this.studentList.length === 0) {
            this.$alert({ content: '目前没有学员，请增加学员' })
          } else {
            switch (type) {
              case 'schedule':
                this.goSchedule()
                break
              case 'course':
                this.goCourse()
                break
              case 'adjust-course':
                this.goAdjustCourse()
                break
            }
          }
        })
      }
    },
    showStudents(selectType) {
      this.loadStudent().then(() => {
        if (this.studentList.length === 0) {
          this.$alert({ content: '目前没有学员，请增加学员' })
        } else {
          this.selectType = selectType
          this.selectedStudent = this.currentStudent.studentId
          this.selectSure(this.selectType)
        }
      })
    },
    selectSure() {
      switch (this.selectType) {
        case 'report':
          this.goReport()
          break
        case 'feedback':
          this.goFeedback()
          break
      }
    },
    goCourse() {
      this.$router.push('/course')
    },
    goAssessment() {
      this.$router.push('/assessment')
    },
    goAdjustCourse() {
      this.$router.push('/adjust-course')
    },
    goSchedule() {
      this.$router.push('/schedule')
    },
    goReport() {
      let studentId = this.selectedStudent
      let studentName = ''
      for (let item of this.studentList) {
        if (item.studentId === this.selectedStudent) {
          studentName = item.studentName
          break
        }
      }
      let areamTeamId = this.areamTeamId
      let url = encodeURI(
        conf.report +
          '#/report?' +
          'areamTeamId=' +
          areamTeamId +
          '&accessToken=' +
          this.accessToken
      )
      if (!studentId) {
        this.$alert({ content: '请选择学生' })
        return
      }
      window.location.href = url
    },
    goFeedback() {
      let studentId = this.selectedStudent
      if (!studentId) {
        this.$alert({ content: '请选择学生' })
        return
      }
      let url = `${conf.feedback}#/list?accessToken=${
        this.accessToken
      }&areamTeamId=${this.areamTeamId}`
      window.location.href = url
    }
  }
}
</script>
<style lang="less" scoped>
.service {
  width: 100%;
  height: 100%;
  background-color: #fff;
  padding-top: 46px;
  .header {
    width: 668px;
    height: 362px;
    margin: 0 auto;
    background: url('../assets/img/home/homeBanner.png');
    background-size: 100% 100%;
    box-shadow: 0px 14px 24px 0px rgba(0, 75, 167, 0.09);
    border-radius: 10px;
    p {
      font-size: 36px;
      color: #333;
      span {
        padding-bottom: 52px;
        border-bottom: 4px solid #333;
      }
    }
  }
  .service-list {
    margin-top: 134px;
    font-size: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    .list-box {
      width: 100%;
      position: relative;
      margin: 0 92px;
    }
    .listOne {
      border-bottom: 1px solid rgba(223, 222, 222, 0.5);
    }
    .listTwo {
      margin-top: 38px;
      border-bottom: 1px solid rgba(223, 222, 222, 0.5);
    }
    .listThree {
      margin-top: 38px;
    }
    ul {
      display: flex;
      padding-bottom: 38px;
      flex-wrap: wrap;
      .liEmpty {
        height: 0;
      }

      li {
        width: 120px;
        margin-right: 28px;
        &:nth-child(4n) {
          margin-right: 0;
        }
        &:nth-child(-n + 4) {
          margin-top: 0;
        }
        div {
          width: 100px;
          margin: 0 auto;
          // background: #2980ff;
          color: #fff;
          display: flex;
          align-items: center;
          justify-content: center;
          border-radius: 50%;
          &.linshi {
            color: #f6b436;
          }
          &.course-s {
            color: #2a7ee4;
          }
          &.school,
          &.xuanke {
            color: #f68c36;
          }
          &.schdule {
            color: #2a7ee4;
          }
          &.report {
            color: #2a7ee4;
          }
          &.feed {
            color: #2a7ee4;
          }
          &.self {
            background: #3271f1;
          }
          &.addStudentIcon {
            color: #f6b436;
          }
          &.pinggu {
            color: #f6b436;
          }
          .iconFont {
            font-size: 70px;
            // width: 70px;
            // height: 60px;
          }
        }
        p {
          text-align: center;
          font-size: 24px;
          height: 24px;
          line-height: 24px;
          margin-top: 22px;
          font-weight: 500;
          color: #060606;
        }
      }
    }
  }
}
.mask {
  position: fixed;
  background: black;
  opacity: 0.2;
  width: 100%;
  height: 100%;
  z-index: 998;
  top: 0;
  left: 0;
}

.select-body {
  max-width: 606px;
  height: 720px;
  position: fixed;
  top: 0;
  left: 60px;
  bottom: 0;
  right: 60px;
  margin: auto;
  padding: 0px;
  z-index: 999;
  border-radius: 20px;
  background-color: #fff;
  box-shadow: 0 60px 360px rgba(0, 0, 0, 0.5);
}

.select-title {
  height: 84px;
  padding: 0 30px;
  margin-bottom: 20px;
  color: #fff;
  background: #01a9ea;
  font-size: 28px;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.select-title img {
  width: 44px;
  margin-right: 20px;
}

.student-list {
  text-align: left;
  overflow: auto;
  height: 480px;
  margin-left: 32px;
  font-size: 0;
  .empty {
    font-size: 28px;
    color: #333;
  }
}

.select-btn {
  position: absolute;
  width: 100%;
  left: 0;
  bottom: 0;
  border-top: 2px solid #ccc;
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
  display: flex;
  display: -webkit-flex;
}

.select-btn div {
  flex: 1;
  -webkit-box-flex: 1;
  text-align: center;
  font-size: 32px;
  color: #999;
  height: 96px;
  line-height: 96px;
}
.select-btn .cancle {
  border-right: 1px solid #ccc;
}
.sure {
  color: #2ba6e1 !important;
}

.student {
  display: inline-block;
  position: relative;
  font-size: 12px;
  width: 50%;
  margin-bottom: 10px;
}

.student input {
  width: 100%;
  height: 28px;
  position: absolute;
  opacity: 0;
  top: 50%;
  transform: translateY(-50%);
}

.student span {
  font-size: 28px;
  color: rgb(100, 100, 100);
  vertical-align: middle;
  margin-left: 6px;
}

.student input:checked + label {
  background-image: url(../assets/img/choose_blue@3x.png);
}

.student label {
  background-image: url(../assets/img/choose_empty@3x.png);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  display: inline-block;
  height: 35px;
  width: 35px;
  position: relative;
  top: 16px;
  margin-right: 6px;
}

.student input {
  opacity: 0;
  z-index: 1;
  position: absolute;
  top: 30px;
  width: 100%;
  height: 54px;
}

.to-bind {
  float: right;
  clear: both;
}

.to-bind img {
  margin-right: 0;
}
</style>
